<template>
	<view class="motion-page page">
		<image class="top-bg" :src="cloudStorage+'index/top-bg.png'"></image>
		<CustomNav :isBack="true" :color="titleColor" :topBgColor="topBgColor" title="大美肃州"></CustomNav>
		<view class="content-block">
			<template v-if="list.length>0">
				<view @click="navigate(item.type==2?'/page_pack/motion_video/detail?id='+item.id:'')" class="video-item"
					v-for="item in list" :key="item.id">
					<video v-if="item.type==1" :id="'video-'+item.id" :src="item.videoUrl" class="video"></video>
					<image v-if="item.type==2" mode="aspectFill" :src="item.coverImage" class="video"></video>
						<view class="video-title">{{item.title}}</view>
				</view>
			</template>
			<view v-if="more==false&&list.length==0" class="empty">暂无数据</view>
			<view v-else-if="more==false&&list.length>0" class="empty">没有更多了</view>
		</view>
	</view>
</template>

<script>
	import {
		isMore
	} from '@/util/util'
	import {
		videoList
	} from '@/api/video'
	export default {
		data() {
			return {
				conf: {
					page: 1,
					limit: 20,
					videoType: 2,
					keyword: ''
				},
				more: true,
				titleColor: '#000',
				topBgColor: 'rgba(0,0,0,0)',
				list: [

				],
			}
		},
		methods: {
			handleRefresh() {
				this.conf.page = 1;
				this.more = true
				this.getList('refresh');
			},
			getList(type = '') {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				videoList(this.conf).then(res => {
					this.list = type == 'refresh' ? res.list : [...this.list, ...res.list];
					this.more = isMore(this.conf.page, this.conf.limit, res.count)
				}).finally(() => {
					uni.stopPullDownRefresh();
				})
			}
		},
		onPullDownRefresh() {
			this.handleRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.conf.page++;
				this.getList();
			}
		},
		onLoad() {
			this.getList('refresh');
		}
	}
</script>

<style lang="scss" scoped>
	.empty {
		width: 100%;
	}

	.motion-page {
		width: 100%;

		.top-bg {
			width: 100%;
			height: 480rpx;
		}

		.content-block {
			position: relative;
			margin-top: -50rpx;
			width: 100%;
			border-radius: 20px 20px 0 0;
			background: #F7F6F9;
			padding: 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			flex-wrap: wrap;
			min-height: 60vh;

			.video-item {
				width: calc(50% - 15rpx);
				display: flex;
				flex-direction: column;
				border-radius: 8px;
				overflow: hidden;
				background: #fff;
				height: 460rpx;
				margin-bottom: 30rpx;

				.video {
					width: 100%;
					height: 340rpx;
				}

				.video-title {
					width: 100;
					display: -webkit-box;
					overflow: hidden;
					text-overflow: ellipsis;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					padding: 20rpx;
					padding-bottom: 0;
				}
			}
		}
	}
</style>